<?php
/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-07-10 23:59:20 +0200 (Thu, 10 Jul 2008) $
 * $Rev: 1285 $
 * $Author: gavinspearhead $
 * $Id: prefs.php 1285 2008-07-10 21:59:20Z gavinspearhead $
 */
define('ORIGINAL_PAGE', $_SERVER['PHP_SELF']);

$pathpr = realpath(dirname(__FILE__));


require_once "$pathpr/../functions/html_includes.php";
require_once "$pathpr/../functions/pref_functions.php";

$languages = array_map('htmlentities', get_languages());

if (isset($_POST['submit_button'])) {
    verify_challenge($_POST['challenge']);

	$db->escape($_POST['language']); // Global escape.
    $language_msg = set_and_test_pref_array('language', $userID, array_keys($languages));
    if ($language_msg == '') {
        unset($LN);
        foreach($smarty->get_template_vars() as $k=>$v) {
            if (substr($k, 0, 3) == 'LN_') {
                $smarty->clear_assign($k);
            }
        }
        load_language($_POST['language']);
    }
}

$searchbuttons = array_map('htmlentities', get_buttons($db));
$level_array = get_user_levels();

$templates = get_templates();

$search_type_array = array(
	'LIKE' => $LN['search_type_like'],
	'REGEXP' => $LN['search_type_regexp']
);


$imported = $saved = 0;
$sort_array = array(
	'better_subject ASC'  => $LN['browse_subject'] . ' - ' . $LN['ascending'],
	'better_subject DESC' => $LN['browse_subject'] . ' - ' . $LN['descending'],
	'Date DESC'     => $LN['browse_age'] . ' - ' . $LN['ascending'], // need to be inverted as we sort on timestamp, not age
	'Date ASC'    => $LN['browse_age'] . ' - ' . $LN['descending'],
	'Size ASC'     => $LN['size'] . ' - ' . $LN['ascending'],
	'Size DESC'    => $LN['size'] . ' - ' . $LN['descending']
);
$index_page_array = get_index_page_array($isadmin);

$dlpath = get_dlpath($db);
$scripts_path = $dlpath . SCRIPTS_PATH;


function get_scripts(DatabaseConnection $db, $dir,  $username = '', $global = TRUE)
{
	if ($global == TRUE)
		$scripts = get_pref($db,'global_scripts', $username, '');
	else 
		$scripts = get_pref($db, 'user_scripts', $username, '');
	$scripts = explode("\n", $scripts);
	if ($global === TRUE)
		$files = glob("$dir/*." . URDD_SCRIPT_EXT);
	else 
		$files = glob("$dir/$username/*." . URDD_SCRIPT_EXT);
	$filenames = array();
	sort($files);

	foreach ($files  as $fn) {
		if ($fn == '') 
			continue;
		$fn = basename($fn);
		$file['on'] = (int)in_array($fn, $scripts);
		$file['name'] = $fn;
		$file['id'] = $fn;
		$filenames[] = $file;
	}
		
	return $filenames;
}

$shaping_msg = $unrar_msg = $unpar_msg = $auto_expire_msg = $password_msg = $index_page_msg = $cancel_crypted_rars_msg = '';
$delete_files_msg = $urdd_restart_msg = $nntp_useauth_msg = $hiddenfiles_msg = $mail_user_msg = $download_text_file_msg = '';
$search_type_msg = $use_auto_download_msg = $skip_int_msg = $delete_account_msg = $max_tasks1_msg = $max_task2_msg = '';

if (isset($_SESSION['urd_username']))
	$thisuser = $_SESSION['urd_username'];
else if (isset($_COOKIE['urd_username']))
	$thisuser = $_COOKIE['urd_username'];
else 
	redirect('login.php');

$dbthisuser = $thisuser;
$db->escape($dbthisuser, TRUE);

$res = $db->select_query("\"ID\" FROM users WHERE \"name\" = $dbthisuser");
if ($res === FALSE) 
	fatal_error($LN['error_haxor']);
$userID = $res[0]['ID'];

update_settings($db, $userID);

$sendmail = get_config($db, 'sendmail');
$auto_download = get_config($db, 'auto_download');
$allow_global_scripts= get_config($db, 'allow_global_scripts');
$allow_user_scripts= get_config($db, 'allow_user_scripts');

// Save changes:
if (isset($_POST['delete_account']) == 'on') {
    verify_challenge($_POST['challenge']);
    delete_user($db, $userID);
    $__message[] = $LN['account_deleted'];
    $smarty->assign('__message',		$__message);
    $smarty->assign('title', 		$LN['urdname'] . ' - ' . $LN['pref_title']);
    $smarty->assign('heading', 		$LN['pref_title']);
    $smarty->assign('menu',			generate_menu($LN));
    $smarty->display('blank.tpl');
    redirect('logout.php', 5);
}

if (isset($_POST['save_settings'])){
	header('Content-Type: text/html/force-download');
	header("Content-Disposition: attachment; filename=urd_user_settings_$thisuser.xml");
    $xml = new urd_xml_writer('php://output');
    $xml->write_user_settings($db, $userID);
    $xml->output_xml_data();
	die;
}

if(isset($_POST['load_settings']) && isset ($_FILES['filename']['tmp_name'])) {
    verify_challenge($_POST['challenge']);
    $xml = new urd_xml_reader($_FILES['filename']['tmp_name']);
    $settings = $xml->read_user_settings($db);
    reset($settings);

	if ($settings != array()) {
		clean_pref($db, $userID); // remove all settings for user
		reset_pref($db, $userID); // restore the default settings
		set_prefs($db, $userID, current($settings)); // overwrite with loaded settings
		$imported = 1;
	} else {
		$__message[] = $LN['settings_notfound'];
	}
}


if (isset($_POST['submit_button'])) {
    verify_challenge($_POST['challenge']);

	$db->escape($_POST); // Global escape.
    $mail_user_msg = set_and_test_pref_bool('mail_user', $userID, $foo);
	$use_auto_download_msg = set_and_test_pref_bool('use_auto_download', $userID, $foo);
	$download_text_file_msg = set_and_test_pref_bool('download_text_file', $userID, $foo);
	$screen_height_msg = set_and_test_pref_numeric('screen_height', $userID, 0);
	$screen_width_msg = set_and_test_pref_numeric('screen_width', $userID, 0);
	$maxsetname_msg = set_and_test_pref_numeric('maxsetname', $userID, 1);
	$minsetsize_msg = set_and_test_pref_numeric('minsetsize', $userID, 0);
	$maxsetsize_msg = set_and_test_pref_numeric('maxsetsize', $userID, 0);
	$minngsize_msg = set_and_test_pref_numeric('minngsize', $userID, 0);
	$taskmax1_msg = set_and_test_pref_numeric('taskmax1', $userID, 1);
	$taskmax2_msg = set_and_test_pref_numeric('taskmax2', $userID, 1);
	$rarfile_size_msg = set_and_test_pref_numeric('rarfile_size', $userID, 0);
	$recovery_size_msg = set_and_test_pref_numeric('recovery_size', $userID, 0);
	$setsperpage_msg = set_and_test_pref_numeric('setsperpage', $userID, 1);
	$setcompleteness_msg = set_and_test_pref_numeric('setcompleteness', $userID, 0, 100);
	$defaultsort_msg = set_and_test_pref_sort('defaultsort', $userID, array_keys($sort_array));
	$hidden_files_list_msg = set_and_test_pref_text_area('hidden_files_list', $userID, TRUE);
	$search_type_msg = set_and_test_pref_array('search_type', $userID, array_keys($search_type_array));
	$search_terms_msg = set_and_test_pref_text_area('search_terms', $userID, TRUE);
	$blocked_terms_msg = set_and_test_pref_text_area('blocked_terms', $userID, TRUE);
    $poster_name_msg = set_and_test_pref_text('poster_name', $userID, NULL, TRUE);
    $format_dl_dir_msg = set_and_test_pref_text('format_dl_dir', $userID, NULL, TRUE);
    $poster_email_msg = set_and_test_pref_text('poster_email', $userID, NULL, TRUE);
    $subs_lang_msg = set_and_test_pref_text('subs_lang', $userID, NULL, TRUE);
    $cancel_crypted_rars_msg = set_and_test_pref_bool('cancel_crypted_rars', $userID, $foo);

	try {
		if ($search_terms_msg == '') {
			mark_search($db, $userID, 'statusint', NULL);
			mark_search_rss($db, $userID, 'statusint', NULL);
		}
		if ($blocked_terms_msg == '') {
			mark_search($db, $userID, 'statuskill', NULL);
			mark_search_rss($db, $userID, 'statuskill', NULL);
		}
	} catch (exception $e) {
		$__message[] = $e->getmessage();
	}

	$delete_files_msg = set_and_test_pref_bool('delete_files', $userID, $foo);
	$unrar_msg = set_and_test_pref_bool('unrar', $userID, $foo);
	$skip_int_msg = set_and_test_pref_bool('skip_int', $userID, $foo);
	$hiddenfiles_msg = set_and_test_pref_bool('hiddenfiles', $userID, $foo);
	$unpar_msg = set_and_test_pref_bool('unpar', $userID, $foo);
	$buttons_msg = set_and_test_pref_buttons('buttons', $userID, $searchbuttons);
    $user_scripts_msg = set_and_test_pref_scripts($scripts_path . $thisuser . '/', 'user_scripts', $userID);
	$global_scripts_msg = set_and_test_pref_scripts($scripts_path, 'global_scripts', $userID);
	$template_msg = set_and_test_pref_array('template', $userID, array_keys($templates));
	$pref_level_msg = set_and_test_pref_array('pref_level', $userID, array_keys($level_array));
	
	$index_page_msg = set_and_test_pref_array('index_page', $userID, array_keys($index_page_array));
	/// todo refresh page if template or lang changed.

	$oldpass  = isset ($_POST['oldpass'])  ? $_POST['oldpass']  : '';
	$newpass1 = isset ($_POST['newpass1']) ? $_POST['newpass1'] : '';
	$newpass2 = isset ($_POST['newpass2']) ? $_POST['newpass2'] : '';
	if ($oldpass != '' && $newpass1 != '' && $newpass2 != '') {
		if ($newpass1 != $newpass2)
			$password_msg = make_error_msg($LN['error_pwmatch'], 'Error');
		else {
			if (($pmsg = verify_password($newpass1, $thisuser)) === TRUE ) {
				$oldpass = hash('sha256', $oldpass);
				$res = $db->select_query("\"name\" FROM users WHERE \"ID\"='$userID' AND \"pass\" = '$oldpass'");
				if ($res === FALSE)
					$password_msg = make_error_msg($LN['error_pwincorrect']);
				else {
					set_password($db, $userID, $newpass1);
					if (isset($_SESSION['urd_period']))
						$period = $_SESSION['urd_period'];
					if (isset($_COOKIE['urd_period']))
						$period = $_COOKIE['urd_period'];
					if (!isset($period))
						$period = 0;
					$pwhash =  hash('sha256', $newpass1);
					$_SESSION['urd_pass'] = $pwhash;
					setcookie('urd_pass', $pwhash, max(time() + 3600, $period));
				}
			} else
				$password_msg = make_error_msg($pmsg);
		}
	} else if ($oldpass != '' && ($newpass1 != '' || $newpass2 != '')) 
        $password_msg = make_error_msg($LN['error_pwincorrect']);
	$saved = 1;
} else if (isset($_POST['reset'])) {
	verify_challenge($_POST['challenge']);
	reset_pref($db, $userID);
}

// First, we get the current values:

$prefArray = load_prefs_clean($db, $userID);

$global_scripts_array = get_scripts($db, $scripts_path, $thisuser, TRUE);
$user_scripts_array = get_scripts($db, $scripts_path, $thisuser, FALSE);

// test if the current settings are correct
if (!isset($pref_level_msg))
	$pref_level_msg = verify_array($prefArray['pref_level'], array_keys($level_array));
if (!isset($language_msg))
	$language_msg = verify_array($prefArray['language'], array_keys($languages));
if (!isset($template_msg))
	$template_msg = verify_array($prefArray['template'], array_keys($templates));
if (!isset($index_array_msg))
	$index_array_msg = verify_array($prefArray['index_page'], array_keys($index_page_array));
if (!isset($search_type_msg))
	$search_type_msg = verify_array($prefArray['search_type'], array_keys($search_type_array));
if (!isset($search_terms_msg))
	$search_terms_msg = verify_text_area($prefArray['search_terms']);
if (!isset($blocked_terms_msg))
	$blocked_terms_msg = verify_text_area($prefArray['blocked_terms']);
if (!isset($hidden_files_list_msg))
	$hidden_files_list_msg = verify_text_area($prefArray['hidden_files_list']);
if (!isset($defaultsort_msg))
	$defaultsort_msg = verify_sort($prefArray['defaultsort'], array_keys($sort_array));
if (!isset($minsetsize_msg))
	$minsetsize_msg = verify_numeric($prefArray['minsetsize'],0);
if (!isset($maxsetsize_msg))
	$maxsetsize_msg = verify_numeric($prefArray['maxsetsize'],0);
if (!isset($minngsize_msg))
	$minngsize_msg = verify_numeric($prefArray['minngsize'],0);
if (!isset($screen_width_msg))
	$screen_width_msg = verify_numeric($prefArray['screen_width'],0);
if (!isset($screen_height_msg))
	$screen_height_msg = verify_numeric($prefArray['screen_height'],0);
if (!isset($setsperpage_msg))
	$setsperpage_msg = verify_numeric($prefArray['setsperpage'],1);
if (!isset($maxsetname_msg))
	$maxsetname_msg = verify_numeric($prefArray['maxsetname'],1);
if (!isset($taskmax1_msg))
	$taskmax1_msg = verify_numeric($prefArray['taskmax1'],1);
if (!isset($taskmax2_msg))
	$taskmax2_msg = verify_numeric($prefArray['taskmax2'],1);
if (!isset($recovery_size_msg))
	$recovery_size_msg = verify_numeric($prefArray['recovery_size'],0);
if (!isset($rarfile_size_msg))
	$rarfile_size_msg = verify_numeric($prefArray['rarfile_size'],0);

if (!isset($subs_lang_msg)) 
    $subs_lang_msg = verify_text_opt('subs_lang', TRUE, NULL);
if (!isset($poster_name_msg)) 
    $poster_name_msg = verify_text_opt('poster_name', TRUE, NULL);
if (!isset($format_dl_dir_msg)) 
    $format_dl_dir_msg = verify_text_opt('format_dl_dir', TRUE, NULL);
if (!isset($poster_email_msg)) 
    $poster_email_msg = verify_text_opt('poster_email', TRUE, NULL);
if (!isset($setcompleteness_msg))
	$setcompleteness_msg = verify_numeric($prefArray['setcompleteness'],0,100);

if (!isset($global_scripts_msg))
	$global_scripts_msg = '';
if (!isset($user_scripts_msg))
	$user_scripts_msg = '';

if (!isset($buttons_msg)) {
	$buttons_msg = '';
	foreach($prefArray as $k => $p) {
		if (preg_match('/^button[0-9]+$/', $k) && $p !='none')
			$buttons_msg = verify_searchbutton($prefArray["$k"], $searchbuttons);
	}
}

$cur_buttons = array();
foreach($prefArray as $k => $p) {
	if (preg_match('/^button[0-9]+$/', $k) && $p != 'none')
		$cur_buttons[] = $p;
}

foreach($searchbuttons as $k => $button) 
	$button_array [$k] = array('name'=>utf8_decode($button), 'on'=>0, 'id'=>$k);

foreach($cur_buttons as $b)
	if (is_numeric($b))
		$button_array[(int)$b]['on'] = 1 ;

$search_terms = ($prefArray['search_terms']);
$search_terms = clean_textarea_data($search_terms);

$blocked_terms = ($prefArray['blocked_terms']);
$blocked_terms = clean_textarea_data($blocked_terms);

$hidden_files_list = ($prefArray['hidden_files_list']);
$hidden_files_list = clean_textarea_data($hidden_files_list);
$hidden_files_list = clean_list($hidden_files_list);

$login = array(
	new pref_plain(CONFIG_LEVEL_BASIC, $LN['username'],$LN['username_msg'],  $thisuser, NULL, NULL),
	new pref_password(CONFIG_LEVEL_BASIC, $LN['oldpw'], 'oldpass', $LN['oldpw_msg'] ,  $password_msg,'' , TEXT_BOX_SIZE),
	new pref_password (CONFIG_LEVEL_BASIC, $LN['newpw'] . ' (1)', 'newpass1', $LN['newpw1_msg'] , '', '', TEXT_BOX_SIZE),
	new pref_password (CONFIG_LEVEL_BASIC, $LN['newpw'] . ' (2)', 'newpass2', $LN['newpw2_msg'] , '', '', TEXT_BOX_SIZE),
	new pref_select (CONFIG_LEVEL_BASIC,  $LN['pref_index_page'], 'index_page', $LN['pref_index_page_msg'], $index_page_msg,  $index_page_array, $prefArray['index_page']),
    new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['delete_account'], 'delete_account', $LN['delete_account_msg'] , $delete_account_msg, 0, 
    'onclick="javascript:confirm_delete_account(\'delete_account\', \'' . $LN['delete_account'] . '?\');"', 'delete_account', NULL),
);

$display = array (
	new pref_select (CONFIG_LEVEL_ALWAYS, $LN['pref_level'], 'pref_level',$LN['pref_level_msg'] ,$pref_level_msg, $level_array, $prefArray['pref_level'] ),
	new pref_select (CONFIG_LEVEL_BASIC, $LN['pref_language'], 'language', $LN['pref_language_msg'], $language_msg, $languages, $prefArray['language']),
	new pref_select (CONFIG_LEVEL_ADVANCED, $LN['pref_template'], 'template', $LN['pref_template_msg'], $template_msg, $templates, $prefArray['template']),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['maxsetname'], 'maxsetname',$LN['maxsetname_msg'], $maxsetname_msg, $prefArray['maxsetname'], NUMBER_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['setsperpage'], 'setsperpage',$LN['setsperpage_msg'], $setsperpage_msg, $prefArray['setsperpage'], NUMBER_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['minsetsize'], 'minsetsize',$LN['minsetsize_msg'], $minsetsize_msg, $prefArray['minsetsize'], NUMBER_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['maxsetsize'], 'maxsetsize',$LN['maxsetsize_msg'], $maxsetsize_msg, $prefArray['maxsetsize'], NUMBER_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['minngsize'], 'minngsize',$LN['minngsize_msg'], $minngsize_msg, $prefArray['minngsize'], NUMBER_BOX_SIZE) ,
	new pref_text (CONFIG_LEVEL_ADVANCED, $LN['taskmax1'], 'taskmax1',$LN['taskmax1_msg'], $taskmax1_msg, $prefArray['taskmax1'], NUMBER_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_ADVANCED, $LN['taskmax2'], 'taskmax2',$LN['taskmax2_msg'], $taskmax2_msg, $prefArray['taskmax2'], NUMBER_BOX_SIZE ),
	new pref_select (CONFIG_LEVEL_BASIC, $LN['defaultsort'], 'defaultsort', $LN['defaultsort_msg'], $defaultsort_msg, $sort_array, $prefArray['defaultsort']),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['pref_setcompleteness'], 'setcompleteness', $LN['pref_setcompleteness_msg'], $setcompleteness_msg,  $prefArray['setcompleteness'], NUMBER_BOX_SIZE),
	new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['skip_int'], 'skip_int',$LN['skip_int_msg'], $skip_int_msg, $prefArray['skip_int']),
	new pref_multiselect (CONFIG_LEVEL_BASIC, $LN['buttons'], 'buttons[]',$LN['buttons_msg'], $buttons_msg, $button_array, 5),
	new pref_text (CONFIG_LEVEL_ADVANCED, $LN['screen_width'], 'screen_width',$LN['screen_width_msg'], $screen_width_msg, $prefArray['screen_width'], NUMBER_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_ADVANCED, $LN['screen_height'], 'screen_height',$LN['screen_height_msg'], $screen_height_msg, $prefArray['screen_height'], NUMBER_BOX_SIZE ),
	new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['hiddenfiles'], 'hiddenfiles',$LN['hiddenfiles_msg'], $hiddenfiles_msg, $prefArray['hiddenfiles'], 'onclick="javascript:toggle_hide(\'hidfil\', \'hidden\')"'),
	new pref_textarea (CONFIG_LEVEL_ADVANCED, $LN['hidden_files_list'], 'hidden_files_list',$LN['hidden_files_list_msg'], $hidden_files_list_msg, $hidden_files_list, 10,40 , NULL, 'hidfil', $prefArray['hiddenfiles']?NULL: 'hidden' )
);

$downloading = array (
	new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['mail_user'], 'mail_user',$LN['mail_user_msg'], $mail_user_msg, $prefArray['mail_user'], NULL, NULL, $sendmail?'':'hidden'),
	new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['unpar'], 'unpar', $LN['unpar_msg'], $unpar_msg, $prefArray['unpar']),
	new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['unrar'], 'unrar',$LN['unrar_msg'], $unrar_msg, $prefArray['unrar']),
	new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['delete_files'], 'delete_files', $LN['delete_files_msg'], $delete_files_msg, $prefArray['delete_files']),
	new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['download_text_file'], 'download_text_file', $LN['download_text_file_msg'], $download_text_file_msg, $prefArray['download_text_file']),
	new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['use_auto_download'], 'use_auto_download', $LN['use_auto_download_msg'], $use_auto_download_msg, $prefArray['use_auto_download'], NULL, NULL, $auto_download?'':'hidden'),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_cancel_crypted_rars'], 'cancel_crypted_rars', $LN['config_cancel_crypted_rars_msg'], $cancel_crypted_rars_msg, $prefArray['cancel_crypted_rars']),
	new pref_select (CONFIG_LEVEL_BASIC, $LN['search_type'],  'search_type', $LN['search_type_msg'], $search_type_msg, $search_type_array, $prefArray['search_type']),
	new pref_textarea (CONFIG_LEVEL_BASIC, $LN['search_terms'], 'search_terms',$LN['search_terms_msg'], '', utf8_decode($search_terms), 10, 40),
	new pref_textarea (CONFIG_LEVEL_BASIC, $LN['blocked_terms'], 'blocked_terms',$LN['blocked_terms_msg'], '', utf8_decode($blocked_terms), 10 , 40),
	new pref_text (CONFIG_LEVEL_ADVANCED, $LN['subs_lang'], 'subs_lang',$LN['subs_lang_msg'], $subs_lang_msg, $prefArray['subs_lang'], TEXT_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_ADVANCED, $LN['format_dl_dir'], 'format_dl_dir',$LN['format_dl_dir_msg'], $format_dl_dir_msg, $prefArray['format_dl_dir'], TEXT_BOX_SIZE ),
);

if ($allow_global_scripts != 0) {
	if (count($global_scripts_array) > 0)
		$downloading[] = new pref_multiselect (CONFIG_LEVEL_ADVANCED, $LN['pref_global_scripts'], 'global_scripts[]', $LN['pref_global_scripts_msg'], $global_scripts_msg, $global_scripts_array, 5);
	if ($allow_user_scripts != 0 && count($user_scripts_array) > 0)
		$downloading[] = new pref_multiselect (CONFIG_LEVEL_ADVANCED, $LN['pref_user_scripts'], 'user_scripts[]', $LN['pref_user_scripts_msg'], $user_scripts_msg, $user_scripts_array, 5);
}


$posting = array (
	new pref_text (CONFIG_LEVEL_BASIC, $LN['poster_email'], 'poster_email',$LN['poster_email_msg'], $poster_email_msg, $prefArray['poster_email'], TEXT_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['poster_name'], 'poster_name',$LN['poster_name_msg'], $poster_name_msg, $prefArray['poster_name'], TEXT_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['recovery_size'], 'recovery_size',$LN['recovery_size_msg'], $recovery_size_msg, $prefArray['recovery_size'], NUMBER_BOX_SIZE ),
	new pref_text (CONFIG_LEVEL_BASIC, $LN['rarfile_size'], 'rarfile_size',$LN['rarfile_size_msg'], $rarfile_size_msg, $prefArray['rarfile_size'], NUMBER_BOX_SIZE ),
);


$pref_list[] = array('name'=>$LN['pref_login'],		    'value'=>$login);
$pref_list[] = array('name'=>$LN['pref_display'],	    'value'=>$display);
$pref_list[] = array('name'=>$LN['pref_downloading'],	'value'=>$downloading);
$pref_list[] = array('name'=>$LN['pref_posting'],	    'value'=>$posting);
 

init_smarty($LN['pref_title']);
$smarty->assign('__message',	$__message);
$smarty->assign('level', 		isset($prefArray['pref_level'])?$prefArray['pref_level']:0);
$smarty->assign('saved', 		$saved);
$smarty->assign('imported', 	$imported);
$smarty->assign('pref_list', 	$pref_list);
$smarty->assign('referrer', 	basename(__FILE__, '.php'));
$smarty->display('settings.tpl');

?>
